package com.lagou.pojo;


import java.util.ArrayList;
import java.util.List;

/**
 * 查询结果
 * @author
 */
public class DataResponse<T> extends BaseResponse{
    /**
     * 数据列表
     */
    private List<T> data;

    /**
     * 数据总数
     */
    private Long total;

    public DataResponse(ResultCode resultCode) {
        super(resultCode);
    }

    public DataResponse(String message) {
        super(message);
    }

    public DataResponse() {
    }

    public void setTotal(Long total) {
        this.total = total;
    }

    /**
     * 只有一条数据
     * @param result
     * @param <T>
     * @return
     */
    public static <T> DataResponse SUCCESS(T result){
        List<T> resultList = new ArrayList<>();
        resultList.add(result);
        DataResponse dataResponse = new DataResponse(ResultCode.SUCCESS);
        dataResponse.setData(resultList);
        dataResponse.setTotal(1L);
        return dataResponse;
    }

    /**
     * list数据
     * @param resultList
     * @param total
     * @param <T>
     * @return
     */
    public static <T> DataResponse SUCCESS(List<T> resultList, long total){
        DataResponse dataResponse = new DataResponse(ResultCode.SUCCESS);
        dataResponse.setTotal(total);
        dataResponse.setData(resultList);
        return dataResponse;
    }

    public List<T> getData() {
        return data;
    }

    public void setData(List<T> data) {
        this.data = data;
    }

    public Long getTotal() {
        return total;
    }
}
